package kz.edu.sdu.atm.util;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Logger {
	String prefix = "";
	PrintWriter stream;

	public enum LoggerType {
		NOTE, WARN, ERROR, DEBUG
	}

	public Logger(){
		try {
			stream = new PrintWriter(new FileWriter("log.txt"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public Logger(String prefix){
		this();
		this.prefix = prefix;
	}
	
	public Logger(Class clazz){
		this(clazz.getName());
	}
	
	public void log(LoggerType t, String s){
		String l = String.format("%s [%s]: %s", t.toString(), prefix, s);
		stream.println(l);
		stream.flush();
		System.out.println(l);
	}

	public void error(String s){
		log(LoggerType.ERROR, s);
	}
	
	public void debug(String s){
		log(LoggerType.DEBUG, s);
	}
	
	public void notice(String s){
		log(LoggerType.NOTE, s);
	}
	
	public void warn(String s){
		log(LoggerType.WARN, s);
	}

}
